
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/18/2012 09:48:28
-- Generated from EDMX file: C:\Users\Adrian\Documents\Visual Studio 2010\Projects\ObligatorioTaller\ObligatorioTaller\Dominio\Dominio.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ObligatorioTaller];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Archivo_inherits_FileSystemElement]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FileSystemElements_Archivo] DROP CONSTRAINT [FK_Archivo_inherits_FileSystemElement];
GO
IF OBJECT_ID(N'[dbo].[FK_BusquedaUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Busquedas] DROP CONSTRAINT [FK_BusquedaUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_RolFuncionalidad_Funcionalidad]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolFuncionalidad] DROP CONSTRAINT [FK_RolFuncionalidad_Funcionalidad];
GO
IF OBJECT_ID(N'[dbo].[FK_RolFuncionalidad_Rol]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolFuncionalidad] DROP CONSTRAINT [FK_RolFuncionalidad_Rol];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioRol]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuarios] DROP CONSTRAINT [FK_UsuarioRol];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Busquedas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Busquedas];
GO
IF OBJECT_ID(N'[dbo].[FileSystemElements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FileSystemElements];
GO
IF OBJECT_ID(N'[dbo].[FileSystemElements_Archivo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FileSystemElements_Archivo];
GO
IF OBJECT_ID(N'[dbo].[Funcionalidades]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Funcionalidades];
GO
IF OBJECT_ID(N'[dbo].[Logs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Logs];
GO
IF OBJECT_ID(N'[dbo].[MetodosIndexacion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MetodosIndexacion];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[RolFuncionalidad]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RolFuncionalidad];
GO
IF OBJECT_ID(N'[dbo].[Usuarios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Usuarios];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'FileSystemElements'
CREATE TABLE [dbo].[FileSystemElements] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ruta] nvarchar(max)  NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [Fecha] datetime  NOT NULL
);
GO

-- Creating table 'Usuarios'
CREATE TABLE [dbo].[Usuarios] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [Apellido] nvarchar(max)  NOT NULL,
    [NombreUsuario] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [RolId] int  NOT NULL
);
GO

-- Creating table 'Busquedas'
CREATE TABLE [dbo].[Busquedas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Keyword] nvarchar(max)  NOT NULL,
    [Cantidad] int  NOT NULL,
    [Usuario_Id] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Funcionalidades'
CREATE TABLE [dbo].[Funcionalidades] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Logs'
CREATE TABLE [dbo].[Logs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Fecha] datetime  NOT NULL,
    [Keyword] nvarchar(max)  NOT NULL,
    [Accion] nvarchar(max)  NOT NULL,
    [UsuarioId] int  NULL
);
GO

-- Creating table 'MetodosIndexacion'
CREATE TABLE [dbo].[MetodosIndexacion] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [NombreClase] nvarchar(max)  NOT NULL,
    [Activa] bit  NOT NULL
);
GO

-- Creating table 'FileSystemElements_Archivo'
CREATE TABLE [dbo].[FileSystemElements_Archivo] (
    [Tamanio] bigint  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'RolFuncionalidad'
CREATE TABLE [dbo].[RolFuncionalidad] (
    [RolFuncionalidad_Funcionalidad_Id] int  NOT NULL,
    [Funcionalidades_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'FileSystemElements'
ALTER TABLE [dbo].[FileSystemElements]
ADD CONSTRAINT [PK_FileSystemElements]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Usuarios'
ALTER TABLE [dbo].[Usuarios]
ADD CONSTRAINT [PK_Usuarios]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Busquedas'
ALTER TABLE [dbo].[Busquedas]
ADD CONSTRAINT [PK_Busquedas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Funcionalidades'
ALTER TABLE [dbo].[Funcionalidades]
ADD CONSTRAINT [PK_Funcionalidades]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Logs'
ALTER TABLE [dbo].[Logs]
ADD CONSTRAINT [PK_Logs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MetodosIndexacion'
ALTER TABLE [dbo].[MetodosIndexacion]
ADD CONSTRAINT [PK_MetodosIndexacion]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FileSystemElements_Archivo'
ALTER TABLE [dbo].[FileSystemElements_Archivo]
ADD CONSTRAINT [PK_FileSystemElements_Archivo]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [RolFuncionalidad_Funcionalidad_Id], [Funcionalidades_Id] in table 'RolFuncionalidad'
ALTER TABLE [dbo].[RolFuncionalidad]
ADD CONSTRAINT [PK_RolFuncionalidad]
    PRIMARY KEY NONCLUSTERED ([RolFuncionalidad_Funcionalidad_Id], [Funcionalidades_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [RolId] in table 'Usuarios'
ALTER TABLE [dbo].[Usuarios]
ADD CONSTRAINT [FK_UsuarioRol]
    FOREIGN KEY ([RolId])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioRol'
CREATE INDEX [IX_FK_UsuarioRol]
ON [dbo].[Usuarios]
    ([RolId]);
GO

-- Creating foreign key on [RolFuncionalidad_Funcionalidad_Id] in table 'RolFuncionalidad'
ALTER TABLE [dbo].[RolFuncionalidad]
ADD CONSTRAINT [FK_RolFuncionalidad_Rol]
    FOREIGN KEY ([RolFuncionalidad_Funcionalidad_Id])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Funcionalidades_Id] in table 'RolFuncionalidad'
ALTER TABLE [dbo].[RolFuncionalidad]
ADD CONSTRAINT [FK_RolFuncionalidad_Funcionalidad]
    FOREIGN KEY ([Funcionalidades_Id])
    REFERENCES [dbo].[Funcionalidades]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RolFuncionalidad_Funcionalidad'
CREATE INDEX [IX_FK_RolFuncionalidad_Funcionalidad]
ON [dbo].[RolFuncionalidad]
    ([Funcionalidades_Id]);
GO

-- Creating foreign key on [Usuario_Id] in table 'Busquedas'
ALTER TABLE [dbo].[Busquedas]
ADD CONSTRAINT [FK_BusquedaUsuario]
    FOREIGN KEY ([Usuario_Id])
    REFERENCES [dbo].[Usuarios]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BusquedaUsuario'
CREATE INDEX [IX_FK_BusquedaUsuario]
ON [dbo].[Busquedas]
    ([Usuario_Id]);
GO

-- Creating foreign key on [Id] in table 'FileSystemElements_Archivo'
ALTER TABLE [dbo].[FileSystemElements_Archivo]
ADD CONSTRAINT [FK_Archivo_inherits_FileSystemElement]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[FileSystemElements]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------